**************
** FIGURE 2 **
**************

clear all

* global inpath = "..." // Insert location of folder containing the dataset here
global inpath = "C:\Users\A1010571\Dropbox (BI Norwegian Business School)\WORKfiles\AFGEWERKTE TEKSTEN\AANVAARD Exit_Voice paper\LSQ"

use "$inpath\Data_for_graphs.dta" 
 
* Figure 2 ALL

foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0, by(OwnParty)
	scalar lower`x'=r(mu_1)-(r(sd_1)/sqrt(r(N_1))*1.96)
	scalar lowerOwn`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upper`x'=r(mu_1)+(r(sd_1)/sqrt(r(N_1))*1.96)
	scalar upperOwn`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

gen lower1 = lowerBecomeIndep_yn if OwnParty==0 & Indep==0
replace lower1 = lowerOwnBecomeIndep_yn if OwnParty==1 & Indep==0
gen lower2 = lowerSetOwnList_yn if OwnParty==0 & Indep==0
replace lower2 = lowerOwnSetOwnList_yn if OwnParty==1 & Indep==0
gen lower3 = lowerLeavePolitics_yn if OwnParty==0 & Indep==0
replace lower3 = lowerOwnLeavePolitics_yn if OwnParty==1 & Indep==0
gen lower4 = lowerPointOthers_yn if OwnParty==0 & Indep==0
replace lower4 = lowerOwnPointOthers_yn if OwnParty==1 & Indep==0

gen upper1 = upperBecomeIndep_yn if OwnParty==0 & Indep==0
replace upper1 = upperOwnBecomeIndep_yn if OwnParty==1 & Indep==0
gen upper2 = upperSetOwnList_yn if OwnParty==0 & Indep==0
replace upper2 = upperOwnSetOwnList_yn if OwnParty==1 & Indep==0
gen upper3 = upperLeavePolitics_yn if OwnParty==0 & Indep==0
replace upper3 = upperOwnLeavePolitics_yn if OwnParty==1 & Indep==0
gen upper4 = upperPointOthers_yn if OwnParty==0 & Indep==0
replace upper4 = upperOwnPointOthers_yn if OwnParty==1 & Indep==0

gen value1 = BecomeIndep_yn if Indep==0
gen value2 = SetOwnList_yn if Indep==0
gen value3 = LeavePolitics_yn if Indep==0
gen value4 = PointOthers_yn if Indep==0

gen ones=1

preserve

reshape long value lower upper, i(id OwnParty) j(category)
collapse (mean) value lower upper, by(OwnParty category)
sort category OwnParty
gen barposition=_n

twoway bar value barposition if(category==1 & OwnParty==0), bcolor(black) || bar value barposition if(category==1 & OwnParty==1), bcolor(black%50) || bar value barposition if(category==2 & OwnParty==0), bcolor(black) ||  bar value barposition if(category==2 & OwnParty==1), bcolor(black%50) ||bar value barposition if(category==3 & OwnParty==0), bcolor(black)||bar value barposition if(category==3 & OwnParty==1), bcolor(black%50)  || bar value barposition if(category==4 & OwnParty==0), bcolor(black)  || bar value barposition if(category==4 & OwnParty==1), bcolor(black%50) || rcap lower upper barposition, lwidth(medthick) lcolor(black) msize(huge) xtitle("") ytitle("") title("All respondents") legend(off) graphregion(fcolor(white)) yscale(range(0(0.05)0.3)) xlabel(1.5 `" "Independent" "(Chi2 = 5.62**)" "' 4.5 `" "Own List" "(Chi2 = 0.02)" "' 7.5 `" "Leave politics" "(Chi2 = 0.99)" "' 10.5 `" "Point to others" "(Chi2 = 0.36)" "') graphregion(margin(l+10 r+10))

restore

drop value* lower* upper* ones

graph save "Graph" "$inpath\figure2all.gph", replace


* Figure 2 MEN

foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==1, by(OwnParty)
	scalar lower`x'=r(mu_1)-(r(sd_1)/sqrt(r(N_1))*1.96)
	scalar lowerOwn`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upper`x'=r(mu_1)+(r(sd_1)/sqrt(r(N_1))*1.96)
	scalar upperOwn`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

gen lower1 = lowerBecomeIndep_yn if OwnParty==0 & Indep==0 & Male==1
replace lower1 = lowerOwnBecomeIndep_yn if OwnParty==1 & Indep==0 & Male==1
gen lower2 = lowerSetOwnList_yn if OwnParty==0 & Indep==0 & Male==1
replace lower2 = lowerOwnSetOwnList_yn if OwnParty==1 & Indep==0 & Male==1
gen lower3 = lowerLeavePolitics_yn if OwnParty==0 & Indep==0 & Male==1
replace lower3 = lowerOwnLeavePolitics_yn if OwnParty==1 & Indep==0 & Male==1
gen lower4 = lowerPointOthers_yn if OwnParty==0 & Indep==0 & Male==1
replace lower4 = lowerOwnPointOthers_yn if OwnParty==1 & Indep==0 & Male==1

gen upper1 = upperBecomeIndep_yn if OwnParty==0 & Indep==0 & Male==1
replace upper1 = upperOwnBecomeIndep_yn if OwnParty==1 & Indep==0 & Male==1
gen upper2 = upperSetOwnList_yn if OwnParty==0 & Indep==0 & Male==1
replace upper2 = upperOwnSetOwnList_yn if OwnParty==1 & Indep==0 & Male==1
gen upper3 = upperLeavePolitics_yn if OwnParty==0 & Indep==0 & Male==1
replace upper3 = upperOwnLeavePolitics_yn if OwnParty==1 & Indep==0 & Male==1
gen upper4 = upperPointOthers_yn if OwnParty==0 & Indep==0 & Male==1
replace upper4 = upperOwnPointOthers_yn if OwnParty==1 & Indep==0 & Male==1

gen value1 = BecomeIndep_yn if Indep==0 & Male==1
gen value2 = SetOwnList_yn if Indep==0 & Male==1
gen value3 = LeavePolitics_yn if Indep==0 & Male==1
gen value4 = PointOthers_yn if Indep==0 & Male==1

gen ones=1

preserve

reshape long value lower upper, i(id OwnParty) j(category)
collapse (mean) value lower upper, by(OwnParty category)
sort category OwnParty
gen barposition=_n

twoway bar value barposition if(category==1 & OwnParty==0), bcolor(black) || bar value barposition if(category==1 & OwnParty==1), bcolor(black%50) || bar value barposition if(category==2 & OwnParty==0), bcolor(black) ||  bar value barposition if(category==2 & OwnParty==1), bcolor(black%50) ||bar value barposition if(category==3 & OwnParty==0), bcolor(black)||bar value barposition if(category==3 & OwnParty==1), bcolor(black%50)  || bar value barposition if(category==4 & OwnParty==0), bcolor(black)  || bar value barposition if(category==4 & OwnParty==1), bcolor(black%50) || rcap lower upper barposition, lwidth(medthick) lcolor(black) msize(huge) xtitle("") ytitle("") title("Male respondents") legend(off) graphregion(fcolor(white)) yscale(range(0(0.05)0.3)) xlabel(1.5 `" "Independent" "(Chi2 = 5.86***)" "' 4.5 `" "Own List" "(Chi2 = 0.05)" "' 7.5 `" "Leave politics" "(Chi2 = 4.06**)" "' 10.5 `" "Point to others" "(Chi2 = 0.65)" "')

restore

drop value* lower* upper* ones

graph save "Graph" "$inpath\figure2men.gph", replace


* Figure 2 WOMEN

foreach x in BecomeIndep_yn SetOwnList_yn LeavePolitics_yn PointOthers_yn {
	ttest `x' if Indep==0 & Male==0, by(OwnParty)
	scalar lower`x'=r(mu_1)-(r(sd_1)/sqrt(r(N_1))*1.96)
	scalar lowerOwn`x'=r(mu_2)-(r(sd_2)/sqrt(r(N_2))*1.96)
	scalar upper`x'=r(mu_1)+(r(sd_1)/sqrt(r(N_1))*1.96)
	scalar upperOwn`x'=r(mu_2)+(r(sd_2)/sqrt(r(N_2))*1.96)
}

gen lower1 = lowerBecomeIndep_yn if OwnParty==0 & Indep==0 & Male==0
replace lower1 = lowerOwnBecomeIndep_yn if OwnParty==1 & Indep==0 & Male==0
gen lower2 = lowerSetOwnList_yn if OwnParty==0 & Indep==0 & Male==0
replace lower2 = lowerOwnSetOwnList_yn if OwnParty==1 & Indep==0 & Male==0
gen lower3 = lowerLeavePolitics_yn if OwnParty==0 & Indep==0 & Male==0
replace lower3 = lowerOwnLeavePolitics_yn if OwnParty==1 & Indep==0 & Male==0
gen lower4 = lowerPointOthers_yn if OwnParty==0 & Indep==0 & Male==0
replace lower4 = lowerOwnPointOthers_yn if OwnParty==1 & Indep==0 & Male==0

gen upper1 = upperBecomeIndep_yn if OwnParty==0 & Indep==0 & Male==0
replace upper1 = upperOwnBecomeIndep_yn if OwnParty==1 & Indep==0 & Male==0
gen upper2 = upperSetOwnList_yn if OwnParty==0 & Indep==0 & Male==0
replace upper2 = upperOwnSetOwnList_yn if OwnParty==1 & Indep==0 & Male==0
gen upper3 = upperLeavePolitics_yn if OwnParty==0 & Indep==0 & Male==0
replace upper3 = upperOwnLeavePolitics_yn if OwnParty==1 & Indep==0 & Male==0
gen upper4 = upperPointOthers_yn if OwnParty==0 & Indep==0 & Male==0
replace upper4 = upperOwnPointOthers_yn if OwnParty==1 & Indep==0 & Male==0

gen value1 = BecomeIndep_yn if Indep==0 & Male==0
gen value2 = SetOwnList_yn if Indep==0 & Male==0
gen value3 = LeavePolitics_yn if Indep==0 & Male==0
gen value4 = PointOthers_yn if Indep==0 & Male==0

gen ones=1

preserve

reshape long value lower upper, i(id OwnParty) j(category)
collapse (mean) value lower upper, by(OwnParty category)
sort category OwnParty
gen barposition=_n

twoway bar value barposition if(category==1 & OwnParty==0), bcolor(black) || bar value barposition if(category==1 & OwnParty==1), bcolor(black%50) || bar value barposition if(category==2 & OwnParty==0), bcolor(black) ||  bar value barposition if(category==2 & OwnParty==1), bcolor(black%50) ||bar value barposition if(category==3 & OwnParty==0), bcolor(black)||bar value barposition if(category==3 & OwnParty==1), bcolor(black%50)  || bar value barposition if(category==4 & OwnParty==0), bcolor(black)  || bar value barposition if(category==4 & OwnParty==1), bcolor(black%50) || rcap lower upper barposition, lwidth(medthick) lcolor(black) msize(huge) xtitle("") ytitle("") title("Female respondents") legend(off) graphregion(fcolor(white)) yscale(range(0(0.05)0.3)) xlabel(1.5 `" "Independent" "(Chi2 = 0.16)" "' 4.5 `" "Own List" "(Chi2 = 0.01)" "' 7.5 `" "Leave politics" "(Chi2 = 1.10)" "' 10.5 `" "Point to others" "(Chi2 = 0.01)" "')

restore

drop value* lower* upper* ones

graph save "Graph" "$inpath\figure2women.gph", replace

graph combine figure2men.gph figure2women.gph, iscale(.6) graphregion(fcolor(white))
graph save "Graph" "$inpath\figure2both.gph", replace
graph combine figure2all.gph figure2both.gph, rows(2) graphregion(fcolor(white)) 